package cn.rocky.offer;

public class offer57 {

    public int[] twoSum(int[] num,int target) {
        int left = 0,right = num.length - 1;
        while(left < right) {
            int s = num[left] + num[right];
            if (s < target) {
                left++;
            } else if (s > target) {
                right--;
            } else {
                return new int[]{num[left],num[right]};
            }
        }
        return new int[0];
    }

    public static void main(String[] args) {
        int[] nums = new int[]{2,7,11,15};
        offer57 offer57 = new offer57();
        int target = 9;
        int[] sum = offer57.twoSum(nums,target);
        System.out.println(sum);
    }
}
